/* model */
import { BaseSelectUserStoreFilterNeedUpdateMapDateType, BaseSelectUserStoreFilterNeedUpdateMapType, BaseSelectUserVuexPropertyEnum } from '@src/component/common/BaseSelectUser/store'
/* store */
import { useBaseSelectUserStore } from '@src/component/common/BaseSelectUser/store/hooks/base'
/* vue */
import { computed } from 'vue'
/* type */
import { 
  BaseSelectUserFilterDepartmentForm, 
  BaseSelectUserFilterRoleForm, 
  BaseSelectUserFilterServiceProviderForm
} from '@src/component/common/BaseSelectUser/types'
/* util */
import { isFilterFormEmpty } from '@src/component/common/BaseSelectUser/util'
import { isFalse, isEmpty, isNotEmpty } from '@src/util/type'

/** 
 * @description 选人控件 筛选表单
*/
function useBaseSelectUserStoreFilterForm() {
  
  const store = useBaseSelectUserStore()
  
  // 筛选部门表单
  const filterDepartmentForm = computed(() => store.state.filterDepartmentForm)
  // 筛选角色表单
  const filterRoleForm = computed(() => store.state.filterRoleForm)
  // 筛选服务商表单
  const filterServiceProviderForm = computed(() => store.state.filterServiceProviderForm)
  
  const setFilterDepartmentForm = (value: BaseSelectUserFilterDepartmentForm) => {
    store.commit(BaseSelectUserVuexPropertyEnum.SetFilterDepartmentForm, value)
  }
  
  const setFilterRoleForm = (value: BaseSelectUserFilterRoleForm) => {
    store.commit(BaseSelectUserVuexPropertyEnum.SetFilterRoleForm, value)
  }
  
  const setFilterServiceProviderForm = (value: BaseSelectUserFilterServiceProviderForm) => {
    store.commit(BaseSelectUserVuexPropertyEnum.SetFilterServiceProviderForm, value)
  }
  
  // 筛选部门表单是否为空
  const isFilterDepartmentFormEmpty = computed(() => {
    return isFilterFormEmpty(filterDepartmentForm.value)
  })
  
  // 筛选部门表单名称是否为空
  const isFilterDepartmentFormTagNameEmpty = computed(() => {
    return isEmpty(filterDepartmentForm.value.tagName)
  })
  
  // 筛选部门表单是否不为空
  const isFilterDepartmentFormNotEmpty = computed(() => {
    return isFalse(isFilterDepartmentFormEmpty.value)
  })
  
  // 筛选角色表单是否为空
  const isFilterRoleFormEmpty = computed(() => {
    return isFilterFormEmpty(filterRoleForm.value)
  })
  
  // 筛选角色表单角色名称是否为空
  const isFilterRoleFormRoleNameEmpty = computed(() => {
    return isEmpty(filterRoleForm.value.roleName)
  })
  
  // 筛选角色表单角色名称是否不为空
  const isFilterRoleFormRoleNameNotEmpty = computed(() => {
    return isNotEmpty(filterRoleForm.value.roleName)
  })
  
  // 筛选角色表单是否不为空
  const isFilterRoleFormNotEmpty = computed(() => {
    return isFalse(isFilterRoleFormEmpty.value)
  })
  
  // 筛选服务商表单是否为空
  const isFilterServiceProviderFormEmpty = computed(() => {
    return isFilterFormEmpty(filterServiceProviderForm.value)
  })
  
  // 筛选服务商表单是否不为空
  const isFilterServiceProviderFormNotEmpty = computed(() => {
    return isFalse(isFilterServiceProviderFormEmpty.value)
  })
  
  return {
    filterDepartmentForm,
    filterRoleForm,
    filterServiceProviderForm,
    
    isFilterDepartmentFormTagNameEmpty,
    isFilterDepartmentFormEmpty,
    isFilterDepartmentFormNotEmpty,
    isFilterRoleFormEmpty,
    isFilterRoleFormNotEmpty,
    isFilterServiceProviderFormNotEmpty,
    
    isFilterRoleFormRoleNameEmpty,
    isFilterRoleFormRoleNameNotEmpty,
    
    setFilterDepartmentForm,
    setFilterRoleForm,
    setFilterServiceProviderForm
  }
}

function useBaseSelectUserStoreFilterNeedUpdateMap() {
  
  const store = useBaseSelectUserStore()
  
  const filterNeedUpdateMap = computed(() => store.state.filterNeedUpdateMap)
  
  const filterNeedUpdateMapDepartment = computed(() => filterNeedUpdateMap.value.Department)
  const filterNeedUpdateMapRole = computed(() => filterNeedUpdateMap.value.Role)
  const filterNeedUpdateMapServiceProvider = computed(() => filterNeedUpdateMap.value.ServiceProvider)
  
  const setFilterNeedUpdateMap = (value: BaseSelectUserStoreFilterNeedUpdateMapType) => {
    store.commit(BaseSelectUserVuexPropertyEnum.SetFilterNeedUpdateMap, value)
  }
  
  const setFilterNeedUpdateMapDepartment = (value: BaseSelectUserStoreFilterNeedUpdateMapDateType) => {
    store.commit(BaseSelectUserVuexPropertyEnum.SetFilterNeedUpdateMapDepartment, value)
  }
  
  const setFilterNeedUpdateMapRole = (value: BaseSelectUserStoreFilterNeedUpdateMapDateType) => {
    store.commit(BaseSelectUserVuexPropertyEnum.SetFilterNeedUpdateMapRole, value)
  }
  
  const setFilterNeedUpdateMapServiceProvider = (value: BaseSelectUserStoreFilterNeedUpdateMapDateType) => {
    store.commit(BaseSelectUserVuexPropertyEnum.SetFilterNeedUpdateMapServiceProvider, value)
  }
  
  return {
    filterNeedUpdateMap,
    filterNeedUpdateMapDepartment,
    filterNeedUpdateMapRole,
    filterNeedUpdateMapServiceProvider,
    setFilterNeedUpdateMapDepartment,
    setFilterNeedUpdateMapRole,
    setFilterNeedUpdateMapServiceProvider,
    setFilterNeedUpdateMap
  }
}

function useBaseSelectUserStoreIsFilterVisible() {
  
  const store = useBaseSelectUserStore()
  
  const isFilterVisible = computed(() => store.state.isFilterVisible)
  
  const setIsFilterVisible = (value: boolean) => {
    store.commit(BaseSelectUserVuexPropertyEnum.SetIsFilterVisible, value)
  }
  
  return {
    isFilterVisible,
    setIsFilterVisible
  }
}

export {
  useBaseSelectUserStoreFilterForm,
  useBaseSelectUserStoreFilterNeedUpdateMap,
  useBaseSelectUserStoreIsFilterVisible
}
